/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package service.enumerations;

/**
 *
 * @author dchapman
 */
public enum RateType {
    FLAT_RATE(0),
    PER_BBL(1),
    PER_DAY(2),
    PER_UNIT(3);
    
    private final int type;

    RateType(final int type) {
        this.type = type;
    }

    public int getType() {
        return type;
    }

    public static RateType getType(final String type) {
        return getType(Integer.parseInt(type));
    }
    
    public static RateType getType(final int type) {
        switch (type) {
        case 0:
            return FLAT_RATE;
        case 1:
            return PER_BBL;
        case 2:
            return PER_DAY;
        case 3:
            return PER_UNIT;
        default:
            throw new EnumConstantNotPresentException(RateType.class, String.valueOf(type));
        }
    }
    
    public static RateType getTypeByName(final String str) {
        if(str.equals("FLAT_RATE")){
            return FLAT_RATE;
        } else if(str.equals("PER_BBL")){
            return PER_BBL;
        } else if(str.equals("PER_DAY")){
            return PER_DAY;
        } else if(str.equals("PER_UNIT")){
            return PER_UNIT;
        } else {
            return FLAT_RATE;
        }
    }
}

